<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title> 
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
    <div id="app">
        <button @click="lang">浪起来</button>
        <button @click="stop">低调</button>
        <h4 style="border: 1px solid red;">{{msg}}</h4>
    </div>
    <script>
        var vm = new Vue({
            el: '#app',
            data:{
                msg: "猥琐发育，别浪~~！",
                intervalId:null
            },
            methods:{
                lang:function(e){
                    /**
                    * ES6的写法，可以不用声明 this。
                    * 在使用剪头函数写法，就可以使用外部的this了
                    */
                    if (this.intervalId == null){
                        this.intervalId = setInterval( () => {
                            var start = this.msg.substring(0,1);
                            var end = this.msg.substring(1);
                            this.msg = end + start;
                        }, 400);
                    }
                },
                stop(e){
                    if (this.intervalId != null){
                        clearInterval(this.intervalId);
                        this.intervalId = null;
                    }
                }
            }    
        });
    </script>
</body>
</html>